#include "SeqQueue.h"
#include <iostream>
#include <stdexcept>

SeqQueue::SeqQueue(){
    seqqueue = new int[MAX_SIZE];
    Front = 0;     //初始化队头队尾
    Rear = 0;
    count = 0;
}

SeqQueue::~SeqQueue(){
    delete[] seqqueue;     //释放空间
}

void SeqQueue::pop_front(){
    if(count == 0){     //下溢错误
        throw std :: overflow_error("QUEUE OVERFLOW");
    }
    Front = (Front + 1) % MAX_SIZE;     //更新队头
    count--;     //数量+1
}

void SeqQueue::push_back(int data){
    if(count == MAX_SIZE){     //上溢错误
        throw std :: overflow_error("QUEUE OVERFLOW");
    }
    seqqueue[Rear] = data;
    Rear = (Rear + 1) % MAX_SIZE;     //更新队尾
    count++;     //数量-1
}

int SeqQueue::front() const{
    if(count == 0){     //下溢错误
        throw std ::underflow_error("QUEUE UNDERFLOW");
    }
    return seqqueue[Front];
}